<html>
<head>
<title>Courses</title>
<!--script src="lib/jquery/jquery-1.3.2.js"--><!--/script-->
<!--script src="http://code.google.com/apis/gears/gears_init.js"--><!--/script-->
<!--script src="js/mainPage.js"--> <!--/script-->

<style type="text/css">
a:link {color:#FFFFFF;}    /* unvisited link */
a:visited {color:#FF0000;} /* visited link */
a:hover {color:#FFFF00;}   /* mouse over link */
a:active {color:#FF8040;}  /* selected link */
</style>

</head>
<!--------------------------------------------------------Design part of the code---------------------------------------------->
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginheight="0" marginwidth="0" bgcolor="#000066">

<table border="0" width="100%" cellspacing="0" cellpadding="0" bgcolor="#000066">
  <tr>
  <td><img src="../images/jsu_banner.jpg"></td>
  </tr>
</table>

<table border="0" width="100%" bgcolor="#000000" cellspacing="0" cellpadding="0">
  <tr>
  <center><td width="100%"><font color="#FFFFFF" face="Arial" size="2"><b>D.O.R.S. Jackson State University Edition</b></font></td></center>
     <?php
	session_start();
	$JNo = $_SESSION['JNo'];
	echo "<center><td width='100%'><font color='#FFFFFF' face='Arial' size='2'><b>JSU ID: $JNo</b></font></td></center>";
  ?>
  </tr>
</table>

<table border="0" width="100%" cellspacing="0" cellpadding="0">
  <tr>
    <td width="18%" bgcolor="#000066" valign="top">&nbsp;


<!------------------------------------------End of Design-------------------------------------------------------->


<center>
<img src="../images/logo.jpg">
</center>

<center>
<img src="../images/courses_sign.jpg">
</center>

<center>
<table>
<tr>
<td><b><a href="http://localhost/OnlineSystem/WebContent/financialAidPage.php">Financial Aid</b></a></td>
<td><b><a href="http://localhost/OnlineSystem/WebContent/accountSummaryPage.php">Account Summary</b></a></td>
<td><b><a href="http://localhost/OnlineSystem/WebContent/purchaseBookPage.php">Purchase Your Books</b></a></td>
<td><b><a href="http://localhost/OnlineSystem/WebContent/selectCourses.php">Choose Courses</b></a></td>
</tr>
</table>
</center>


<center>
<!-- Course Page -->
<table border="3" width="25%" cellspacing="0" cellpadding="0" bgcolor="#F0F8FF">
<tr>
<td><b>Select</b></td>
<td><b>CRN</b></td>
<td><b>Subject</b></td>
<td><b>Course No.</b></td>
<td><b>Section</b></td>
<td><b>Hours</b></td>
<td><b>Title</b></td>
<td><b>Location</b></td>
<td><b>Days</b></td>
<td><b>Time</b></td>
<td><b>Capacity</b></td>
<td><b>Enrolled</b></td>
<td><b>Seats Remaining</b></td>
</tr>

<FORM action= "addCourses.php" method="post"> 
<tr>
	<td>
		<!-- Something about Selecting a course -->
	</td>
	<?php
		$host="localhost"; // Host name
		$username="root"; // Mysql username
		$password=""; // Mysql password
		$db_name="JSU_Database"; // Database name

		// Connect to server and select database.
		mysql_connect($host, $username, $password)or die("cannot connect");
		mysql_select_db($db_name)or die("cannot select DB: ".mysql_error());

		$subjects = $_POST['subjects'];
		$subjectNos = $_POST['subjectNo'];
		if ($subjects[0] != "Course Subjects"){
			for($i=0; $i<count($subjectNos);$i++){
				if ($subjectNos[$i] == null)
					echo "<br>null";
				else
					echo "<br>$subjectNos[$i]";
			}
			for($i=0; $i<count($subjects); $i++){
				echo "<tr><td>$subjects[$i]</td></tr>";
				if ($subjectNos[$i] == null)
					$result = mysql_query ("SELECT * FROM course WHERE CourseSubject = '$subjects[$i]'");
				else
					$result = mysql_query("SELECT * FROM course WHERE CourseSubject = '$subjects[$i]' AND CourseNo = '$subjectNos[$i]'");
				if (!$result)
					echo "<tr><td>No classes for this selection exist!</td></tr>";
				else {
					while ($row = mysql_fetch_row($result)){
						echo "<tr>";
							if ($row[10] <= 0)
								echo "<td>Closed</td>";
							else
								echo "<td><input type='checkbox' name='selectedClasses[]' value='$row[0]'></td>";
							//CRN
							echo "<td>$row[0]</td>";
							//Subject -->
							echo "<td>$row[1]</td>";
							//<!--Course Number-->
							echo "<td>$row[2]</td>";
							//<!-- Section -->
							echo "<td>$row[3]</td>";
							//<!-- Hours -->
							echo "<td>$row[4]</td>";
							//<!-- Title -->
							echo "<td>$row[6]</td>";
							//<!-- Location -->
							echo "<td>$row[11]</td>";
							//Days
							echo "<td>$row[7]</td>";
							//<!-- Time -->
							echo "<td>$row[5]</td>";
							//Capacity
							echo "<td>$row[8]</td>";
							//Enrolled
							echo "<td>$row[9]</td>";
							//Remaining
							echo "<td>$row[10]</td>";
						echo "</tr>";
					}
				}
			}
		}
		else {
			$day = $_POST['day'];
			$time = $_POST['time'];
			// used time and day instead
			$result = mysql_query("SELECT * FROM course WHERE Time LIKE '%$time%' AND Days LIKE '%$day%'");
			if (!$result)
				echo "<tr><td>No classes for this time and day exist!</td></tr>";
			else {
				while ($row = mysql_fetch_row($result)){
					echo "<tr>";
						//Display checkbox or "Closed" notice
						if ($row[10] <= 0)
							echo "<td>Closed</td>";
						else
							echo "<td><input type='checkbox' name='selectedClasses[]' value='$row[0]'></td>";
						//CRN
						echo "<td>$row[0]</td>";
						//Subject -->
						echo "<td>$row[1]</td>";
						//<!--Course Number-->
						echo "<td>$row[2]</td>";
						//<!-- Section -->
						echo "<td>$row[3]</td>";
						//<!-- Hours -->
						echo "<td>$row[4]</td>";
						//<!-- Title -->
						echo "<td>$row[6]</td>";
						//<!-- Location -->
						echo "<td>$row[11]</td>";
						//Days
						echo "<td>$row[7]</td>";
						//<!-- Time -->
						echo "<td>$row[5]</td>";
						//Capacity
						echo "<td>$row[8]</td>";
						//Enrolled
						echo "<td>$row[9]</td>";
						//Remaining
						echo "<td>$row[10]</td>";
					echo "</tr>";
				}
			}
		}
	?>
</table>
</center>

<center>

<INPUT type="button" value="Back" name="button1" onClick="history.go(-1); return true;"> 
<INPUT type="submit" value="Next" name="button2">
</FORM>
</center>

</body>
</html>